﻿using System;

namespace ImprovedPerson
{
    public class Person : IPropertyChangeNotification
    {
        private string firstName;
        private string lastName;
        private string gender;
        private string birthDate;

        public Person(string firstName, string lastName, string gender, string birthDate)
        {
            this.firstName = firstName;
            this.lastName = lastName;
            this.gender = gender;
            this.birthDate = birthDate;
            this.PropertyChanged += OnPropertyChanged;
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(object sender, PropertyChangedEventArgs args)
        {
            Console.WriteLine("{0} property changed from {1} to {2}.", 
                args.PropertyName, args.OldValue, args.NewValue);
        }

        public string FirstName
        {
            get
            {
                return firstName;
            }
            set
            {
                if (value != firstName)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("FirstName", firstName, value));
                    firstName = value;
                }
            }
        }

        public string LastName
        {
            get
            {
                return lastName;
            }
            set
            {
                if (value != lastName)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("LastName", lastName, value));
                    lastName = value;
                }
            }
        }

        public string Gender
        {
            get
            {
                return gender;
            }
            set
            {
                if (value != gender)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("Gender", gender, value));
                    gender = value;
                }
            }
        }

        public string BirthDate
        {
            get
            {
                return birthDate;
            }
            set
            {
                if (value != birthDate)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("BirthDate", birthDate, value));
                    birthDate = value;
                }
            }
        }
    }
}
